#include <iostream>

using namespace std;

void dump(int arr[], int n) {
    for (int i=0; i<n; i++) {
        printf("%4d", arr[i]);
    }
    cout << endl;
}

void quick_sort(int arr[], int low, int high) {
    if (low < high) {
        int i=low;
        int j = high;
        int k = arr[low];
        while (i < j) {
            while (i<j && arr[j]>=k) {
                j--;
            }
            if (i<j) {
                arr[i++] = arr[j];
            }
            while (i<j && arr[i]<k) {
                i++;
            }
            if (i<j) {
                arr[j--] = arr[i];
            }
        }
        arr[i] = k;

        quick_sort(arr, low, i-1);
        quick_sort(arr, i+1, high);
    }
}

void test() {
    int arr[] = {12, 85, 25, 16, 34, 23, 49, 95, 17, 61};
    int len = sizeof(arr) / sizeof(arr[0]);
    dump(arr, len);

    quick_sort(arr, 0, len-1);
    dump(arr, len);
}

int main(int argc, char** argv) {
    test();
    return 0;
}
